const { Unauthorized } = require("http-errors");
const { userSessions } = require("../utils/userInfo");

/**
 * 管理员身份验证中间件
 */
async function adminAuth(req, res, next) {
  try {
    // 检查 session 中是否存在 AcceptToken
    if (req.session && req.session.AcceptToken) {
      // 将 AcceptToken 添加到请求头中
      req.headers.accepttoken = req.session.AcceptToken;
    }

    next();
  } catch (error) {
    next(new Unauthorized("身份验证失败"));
  }
}

module.exports = adminAuth;
